﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace Vent.ViewModels.Tools
{
    [DataContract]
    public class MaskTool : Tool
    {
        public List<Brush> Masks { get; set; }

        public MaskTool()
        {
            Initialize();
        }

        public Brush CurrentMask { get; set; }

        public override void AddPoint(Point point, bool start)
        {
            var canvas = new Canvas
            {
                Width = Tickness,
                Height = Tickness,
                OpacityMask = CurrentMask ?? Masks.FirstOrDefault(),
                Opacity = Opacity,
                Margin = new Thickness(point.X - Tickness/2, point.Y - Tickness/2, 0, 0),
                Background = GetAlignedBrush(point),
            };

            TouchViewModel.AddTouch(canvas);
        }

        [OnDeserialized]
        public new void Initialize(StreamingContext context = default(StreamingContext))
        {
            Masks = new List<Brush>
            {
                new ImageBrush
                {
                    ImageSource =
                        new BitmapImage(new Uri("/Vent;component/Resources/Masks/Ellipse.png", UriKind.Relative))
                },
                new ImageBrush
                {
                    ImageSource = new BitmapImage(new Uri("/Vent;component/Resources/Masks/Star.png", UriKind.Relative))
                },
                new ImageBrush
                {
                    ImageSource =
                        new BitmapImage(new Uri("/Vent;component/Resources/Masks/Rectangle.png", UriKind.Relative))
                },
            };
        }
    }
}
